package com.arrcen.medicen.core.match.utlity;

import com.xxl.job.core.context.XxlJobHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@Service
public class LogHelper {

    long startTime = System.currentTimeMillis();
    int stepInfo =0;

    private Logger getLogger(Class type){
        return LoggerFactory.getLogger(type);
    }

    public void resetTime(){
        stepInfo =1;
        startTime = System.currentTimeMillis();
    }

    /**
     * 记录调度日志
     * @param type
     * @param msg
     */
    public void info(Class type, String msg) {
        Logger logger = getLogger(type);
        long spend = System.currentTimeMillis() - this.startTime;
        logger.info("第{}步 {} 用时 {} 毫秒", stepInfo, msg, spend);
        XxlJobHelper.log("第{}步 {} 用时 {} 毫秒", stepInfo, msg, spend);

        stepInfo++;
    }
    public void info(String msg) {
        Logger logger = getLogger(LogHelper.class);
        long spend = System.currentTimeMillis() - this.startTime;
        logger.info("第{}步 {} 用时 {} 毫秒", stepInfo, msg, spend);
        stepInfo++;
    }


    /**
     * 记录错误日志
     * @param type
     * @param msg
     */
    public void debug(Class type, String msg) {
        Logger logger = getLogger(type);
        long spend = System.currentTimeMillis() - this.startTime;
        logger.info("第{}步 {} 用时 {} 毫秒", stepInfo, msg, spend);
        stepInfo++;
    }
}
